package com.caicf.user;

import com.github.pagehelper.PageHelper;
import com.hirain.fbg.sys.dao.CountryMapper;
import com.hirain.fbg.sys.dao.UserMapper;
import com.hirain.fbg.sys.model.Country;
import com.hirain.fbg.sys.model.User;
import com.hirain.fbg.util.MD5;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.List;

/**
 * Created by caicf on 2016/7/12.
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:spring-mybatis.xml")
public class InsertUser {
    @Autowired
    private UserMapper userMapper;

    @Test
    public void selectUserWithInfos() {
        List<User> users=userMapper.selectUserWithInfos();
        for (User user : users) {
            System.out.println(user.getUsername()+" : "+user.getPassword());
            System.out.println(user.getUserInfos().getGender());
        }
    }

    @Test
    public void selectAllTest() {
        User user=userMapper.selectByPrimaryKey(1);
        System.out.println(user.getUsername());
        System.out.println(user.getPassword());
    }

    @Test
    public void insertUser(){
        User user=new User();
        user.setUserId(1);
        user.setUsername("caicf");
        user.setPassword(MD5.encodeString("123456"));
        userMapper.insert(user);
    }

    @Autowired
    private CountryMapper countryMapper;

    @Test
    public void selectAllCountry() {
        PageHelper.startPage(1,10);

        List<Country> countries=countryMapper.selectAll();
        for (Country country : countries) {
            System.out.println(country.getId()+">>>"+country.getCountryname());
        }
//        PageInfo<Country> pageInfo=new PageInfo<Country>(countries);

    }
}
